//
//  WmcNavView.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/3/1.
//

import UIKit
import YPBedrock

open class WmcNavView: WmcBaseView {
    // Open

    override open func makeUI() {
        addSubview(backImageView)
        backImageView.snp.makeConstraints { make in
            make.top.equalTo(Wmc_statusBarHeight)
            make.bottom.equalToSuperview()
            make.left.equalTo(Wmc_standardEdge.left)
            make.width.equalTo(23)
        }

        addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(Wmc_statusBarHeight)
            make.bottom.right.equalToSuperview()
            make.left.equalTo(backImageView.snp.right).offset(8)
        }

        addSubview(backControl)
        backControl.snp.makeConstraints { make in
            make.top.equalTo(titleLabel)
            make.left.bottom.equalToSuperview()
            make.width.equalToSuperview().multipliedBy(0.33333)
        }

    }
    
    func addShadow() {
        layer.shadowColor = UIColor.black.cgColor
        layer.shadowOffset = CGSize(width: 0, height: 3)
        layer.shadowOpacity = 0.1
        layer.shadowRadius = 3
    }

    // Internal

    lazy var backControl: UIControl = {
        let control = UIControl()

        return control
    }()

    lazy var titleLabel: UILabel = {
        let label = UILabel.YP.Create(font: 22.yp.uiFont(weight: .bold),
                                      color: UIColor.black,
                                      alignment: .left)
        return label
    }()

    lazy var backImageView: UIImageView = {
        let imageView = UIImageView(image: "arrow_left".wmc_image)
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()

    /// 标题
    var title: String? {
        set { titleLabel.text = newValue }
        get { return titleLabel.text }
    }

    /// 设置返回触发范围的宽度
    var backControlWidth: CGFloat = 0 {
        didSet {
            backControl.snp.remakeConstraints { make in
                make.top.equalTo(titleLabel)
                make.left.bottom.equalToSuperview()
                make.width.equalTo(backControlWidth)
            }
        }
    }
}
